//package com.filter;
//
//import java.io.IOException;
//import jakarta.servlet.Filter;
//import jakarta.servlet.FilterChain;
//import jakarta.servlet.FilterConfig;
//import jakarta.servlet.ServletException;
//import jakarta.servlet.ServletRequest;
//import jakarta.servlet.ServletResponse;
//import jakarta.servlet.annotation.WebFilter;
//import jakarta.servlet.http.HttpFilter;
//import jakarta.servlet.http.HttpServletRequest;
//import jakarta.servlet.http.HttpServletResponse;
//import jakarta.servlet.http.HttpSession;
//
///**
// * Servlet Filter implementation class LoginFilter
// */
//@WebFilter("/*") // 拦截所有请求，后续在代码中根据具体规则判断是否放行
//public class LoginFilter extends HttpFilter implements Filter {
//
//	/**
//	 * @see HttpFilter#HttpFilter()
//	 */
//	public LoginFilter() {
//		super();
//		// TODO Auto-generated constructor stub
//	}
//
//	/**
//	 * @see Filter#destroy()
//	 */
//	public void destroy() {
//		// 可根据需要添加销毁相关的资源释放等逻辑，目前为空实现
//	}
//
//	/**
//	 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
//	 */
//	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
//		HttpServletRequest req = (HttpServletRequest) request;
//		HttpServletResponse resp = (HttpServletResponse) response;
//		String reqURL = req.getServletPath();
//
//		HttpSession session = req.getSession();
//		String getSessionUser = (String) session.getAttribute("sess_user");
//
//		if (getSessionUser!= null) {
////			resp.getWriter().print(getSessionUser + "你好！");
//		}
//
//		// 检查是否是允许未登录访问的页面（登录、注册等相关页面）或者已登录状态
//		if (getSessionUser!= null || reqURL.startsWith("/js/") || reqURL.startsWith("/css/") || reqURL.startsWith("/image/")||reqURL.startsWith("/image/illustration-5.svg")||reqURL.equals("/login.jsp") || reqURL.equals("/logincheck.jsp") || reqURL.equals("/register.jsp") || reqURL.equals("/regicheck.jsp")||reqURL.equals("/index.jsp")) {
//			chain.doFilter(request, response);
//		} else {
//			resp.getWriter().print("过滤器无法让你过去，需要先登录");
////			resp.getWriter().print("<a href='login.jsp'>登录</a>");
//		}
//	}
//
//	/**
//	 * @see Filter#init(FilterConfig)
//	 */
//	public void init(FilterConfig fConfig) throws ServletException {
//		// 可根据需要添加初始化相关的配置读取等逻辑，目前为空实现
//	}
//
//}